package com.guaju.yueshangLife.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.res.TypedArray;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.adapter.NoneCommonRecyclerViewAdapter;
import com.guaju.yueshangLife.databinding.ActivityDialogGetCouponlistBinding;
import com.guaju.yueshangLife.recyclerView.BaseRecyclerAdapter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class GetCouponListDialogActivity extends Activity implements View.OnClickListener{
    private static final String TAG = "GUAJU";
    private static final String LIST = "coupon_List";
    //定义Activity退出动画的成员变量
    protected int activityCloseEnterAnimation;
    protected int activityCloseExitAnimation;
    private BaseRecyclerAdapter mAdapter;
    ActivityDialogGetCouponlistBinding binding;
    private List<String> stringList = new ArrayList<String>();
//    private List<AudioBean> audiolist;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding=DataBindingUtil.setContentView(this, R.layout.activity_dialog_get_couponlist);
//        Intent intent = getIntent();
//        Bundle extras = intent.getExtras();
//        Serializable serializable = extras.getSerializable(GetCouponListDialogActivity.LIST);
        protectAnim();
        loadData();
        setListener();
    }

    private void setListener() {
//        binding.close.setOnClickListener(this);
    }

    private void loadData() {
//        NoneCommonRecyclerViewAdapter mAdapter = new NoneCommonRecyclerViewAdapter<AudioBean>(this, R.layout.item_playing_audio, audiolist) {
//            @Override
//            public void convert(BaseViewHolder holder, AudioBean bean) {
//                holder.setText(R.id.playing_audio_title, bean.getTitle());
//                holder.setText(R.id.playing_audio_author,bean.getArtist());
//                holder.setText(R.id.duration, DateUtils.generateTimeBySecond((int) bean.getDuration()));
//
//                holder.itemView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                     //TODO
//                      if (playActivity!=null){
//                          playActivity.setViewData(bean);
//                          Log.e(TAG, "onClick: "+bean.getTitle());
//                          finish();
//                      }
//                    }
//                });
//            }
//        };
//        LinearLayoutManager manager = new LinearLayoutManager(this);
//        binding.recyclerview.setLayoutManager(manager);
//        binding.recyclerview.setAdapter(mAdapter);
    }


    //    解决退出SecondActivity从底部退出动画失效问题
    private void protectAnim() {
        TypedArray activityStyle = getTheme().obtainStyledAttributes(new int[]{android.R.attr.windowAnimationStyle});
        int windowAnimationStyleResId = activityStyle.getResourceId(0, 0);
        activityStyle.recycle();
        setFinishOnTouchOutside(true);//点击空白处，窗体不关闭
        activityStyle = getTheme().obtainStyledAttributes(windowAnimationStyleResId, new int[]{android.R.attr.activityCloseEnterAnimation, android.R.attr.activityCloseExitAnimation});
        activityCloseEnterAnimation = activityStyle.getResourceId(0, 0);
        activityCloseExitAnimation = activityStyle.getResourceId(1, 0);
        activityStyle.recycle();

        //设置布局在底部
        getWindow().setGravity(Gravity.BOTTOM);
        //设置布局填充满宽度
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(layoutParams);
    }

    //    重写finish方法
    @Override
    public void finish() {
        super.finish();
        //finish时调用退出动画
        overridePendingTransition(activityCloseEnterAnimation, activityCloseExitAnimation);
    }



    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.close:
                finish();
                break;

                default:
                    break;
        }
    }
}